package com.cskaoyan.demo7.service;

import com.cskaoyan.demo7.bean.model.MarketComment;
import com.cskaoyan.demo7.bean.model.MarketCommentExample;
import com.cskaoyan.demo7.mapper.MarketCommentMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/22 21:50
 */

@Service("commentService")
public class CommentServiceImpl implements CommentService {
    @Autowired
    private MarketCommentMapper commentMapper;
    @Override
    public List<MarketComment> queryByGoodsId(Integer id) {
        MarketCommentExample commentExample = new MarketCommentExample();
        commentExample.createCriteria().andValueIdEqualTo(id).andTypeEqualTo(((byte) 0)).andDeletedEqualTo(false);
        commentExample.setOrderByClause("add_time desc");
        // 只显示2个评论
        PageHelper.offsetPage(0, 2);
        List<MarketComment> marketComments = commentMapper.selectByExample(commentExample);
        return marketComments;
    }

    @Override
    public Integer countByGoodsId(Integer id) {
        MarketCommentExample commentExample = new MarketCommentExample();
        commentExample.createCriteria().andValueIdEqualTo(id).andTypeEqualTo(((byte) 0)).andDeletedEqualTo(false);
        commentExample.setOrderByClause("add_time desc");
        long count = commentMapper.countByExample(commentExample);
        return (int) count;
    }
}
